package com.mk.settlement.controller;

import java.util.Map;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.common.collect.Maps;
import com.mk.settlement.common.Page;
import com.mk.settlement.model.SettlementSchedulerCenter;
import com.mk.settlement.service.SettlementSchedulerCenterService;

/**
 * futao
 * 任务管理中心
 */
@Controller
@RequestMapping("/sc/rpt/ssc")
public class SettlementSchedulerCenterController {
	private Logger log = LoggerFactory.getLogger(SettlementSchedulerCenterController.class);
	@Autowired
	private SettlementSchedulerCenterService sscService;
	

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> pageQuery(@RequestParam(value = "taskName", required = false)@RequestBody String taskName, Page page ) {
//		System.out.println("taskName=="+taskName);
//		System.out.println(ToStringBuilder.reflectionToString(page));
//		System.out.println("BeginTime=="+page.getBeginTime()+"    EndTime="+page.getEndTime());
		log.info("任务查询数据的参数是：taskName="+taskName);
		log.info("任务查询数据的参数（page）"+ToStringBuilder.reflectionToString(page));
		page = sscService.findData(taskName, page);
		log.info("共查询到"+page.getTotalRecord()+"条数据");
		Map<String, Object> rtnMap = Maps.newHashMap();
		rtnMap.put("result", page.getResult());
		rtnMap.put("page", page);
		return rtnMap;
	}

	 
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> edit(SettlementSchedulerCenter ssc) {
//		System.out.println(ToStringBuilder.reflectionToString(ssc));
		log.info("修改任务传入的参数（SettlementSchedulerCenter）是："+ToStringBuilder.reflectionToString(ssc));
		Map<String, Object> rtnMap = Maps.newHashMap();
		int rs= sscService.updateSettlementSchedulerCenter(ssc);
		log.info("修改完成，共成功修改"+rs+"条任务数据!");
		rtnMap.put("result",rs);
		return rtnMap;
	}
	
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> delete( @RequestParam(value = "id", required = true) @RequestBody Long id ) {
//		System.out.println(" delete----id=="+id);
		log.info("删除任务：传入的ID=="+id);
		Map<String, Object> rtnMap = Maps.newHashMap();
		int rs=sscService.deleteById(id);
		log.info("删除完成，共成功删除"+rs+"条任务数据!");
		rtnMap.put("result",rs );
		return rtnMap;
	}
	
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add( SettlementSchedulerCenter ssc) {
// 		System.out.println(ToStringBuilder.reflectionToString(ssc));
 		log.info("添加新任务，传入参数（SettlementSchedulerCenter）是："+ToStringBuilder.reflectionToString(ssc));
		Map<String, Object> rtnMap = Maps.newHashMap();
		int rs= sscService.insert(ssc);
		log.info("添加完成，共成功添加"+rs+"条任务数据!");
		rtnMap.put("result",rs );
		return rtnMap;
	}

}
